package com.leetcode;

import java.util.*;

/**
 * <p>
 * 按8来进行切割，不足8的补0，满8的切割，得到的结果升序排序。
 * 输入： 2 abc 123456789
 * 输出：12345678 90000000 abc00000
 * </p>
 *
 * @author zhu.chen
 * @date 2021/2/27
 * @version 1.0
 */
public class Multiple8 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String count = scanner.nextLine();
        List<String> list = new ArrayList<>();
        String[] strings = count.split(" ");
        for (int i = 1; i <= strings.length - 1; i++) {
            list.add(strings[i]);
        }
        Set<String> set = new TreeSet<>();
        for (String value : list) {
            int n = value.length() % 8;
            if (n != 0) {
                int length = 8 - value.length() % 8;
                for (int i = 0; i < length; i++) {
                    value = value + "0";
                }
            }
            StringBuffer buffer = new StringBuffer(value);
            while (value.length() % 8 == 0) {
                if (buffer.length() ==0) {
                    break;
                }
                set.add(buffer.substring(0,8));
                buffer.delete(0,8);
            }

        }
        for (String value : set) {
            System.out.print(value + " ");
        }
    }

}
